﻿import com.dmotiko.general.*;
import com.dmotiko.prune.*;
import mx.transitions.easing.Regular;
import mx.transitions.easing.Strong;
import mx.transitions.Tween;
import mx.utils.Delegate;
/**
 * ...
 * @author sminutoli
 */
class MainNews extends BaseClip
{
	
	private var mcMask:MovieClip;
	private var mcContent:MovieClip;
	private var overCheck:MovieClip;
	private var section_listener:Function;
	
	private function initClip():Void {
		this._visible = false;
		this._alpha = 0;
		this.bShowed = false;
		
		overCheck = createEmptyMovieClip( "overCheck", this.getNextHighestDepth() );
		
		mcContent.initY = mcContent._y;
		mcContent.endY = mcContent._y - mcContent.mcBack._height;
		
		mcContent.setMask( mcMask );
		section_listener = Delegate.create( this, section_changed );
		Site.getApp().addEventListener( WebSite.SECTION_CHANGED, section_listener);
	}
	
	private function section_changed(e):Void {
		if ( e.section == SiteSections.HOME ) {
			show();
		} else {
			hide();
		}
	}
	
	public function showNews():Void {
		registerTween( "moveY", new Tween( mcContent, "_y", Strong.easeOut, mcContent._y, mcContent.endY, 0.5, true) );
		Site.getApp().getClips().getShopOnline().hide();
		overCheck.onEnterFrame = function() {
			if ( _parent._xmouse < 0 || _parent._xmouse > _parent.mcContent._width ) {
				_parent.hideNews();
				delete this.onEnterFrame;
			}
		}
	}
	public function hideNews():Void {
		registerTween( "moveY", new Tween( mcContent, "_y", Strong.easeOut, mcContent._y, mcContent.initY, 0.5, true) );
		if( Site.getApp().getSection() == SiteSections.HOME ) Site.getApp().getClips().getShopOnline().show();
	}
	
	public function show():Void {
		mcContent._y = mcContent.initY;
		_visible = true;
		registerTween("show", new Tween( this, "_alpha", Regular.easeOut, this._alpha, 100, 0.5, true), false, true );
		
	}
	public function hide():Void {
		registerTween("hide", new Tween( this, "_alpha", Regular.easeOut, this._alpha, 0, 0.5, true), false, true );
	}
	
	private function tweenFinished( key:String, tween:Tween ):Void {
		switch ( key ) 
		{
			case "show":
			showEnd();
			break;
			
			case "hide":
			_visible = false;
			hideEnd();
			break;
		}
	}
	
}